﻿// -----------------------------------------------------------------------
// <copyright file="MainWindow.xaml.cs" company="Support">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace SupportSystemUpdate
{
    using System.Diagnostics;
    using System.Windows;

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindow"/> class.
        /// </summary>
        public MainWindow()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Handles the Loaded event of the Window control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void Window_Loaded( object sender , RoutedEventArgs e )
        {
            Updater.Instance.LastVersionChanged += () =>
            {
                this.statusLabel.Content = "You are not up to date. Please wait until we download the last version.";
            };

            Updater.Instance.LastVersionDownloaded += () =>
            {
                this.statusLabel.Content = "Download complete. Please wait for extraction.";
            };

            Updater.Instance.LastVersionUpdated += ( status ) =>
            {
                this.statusLabel.Content = status;
                Process.Start( "SupportSystemUI.exe" );
                this.Close();
            };

            Updater.Instance.UpdateVersion( System.IO.Path.GetDirectoryName( Process.GetCurrentProcess().MainModule.FileName ) );
        }
    }
}
